/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package persistence;

import java.io.Serializable;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * This class is a JPA entity and is used to represent an assignment
 * of a ticket done by an administrator to a specific assistant
 * 
 * @author Amigos do Noddy
 *
 */
@Entity
@Table(name = "ASSIGNMENT",schema = "APP")
@NamedQueries({@NamedQuery(name = "Assignment.findByRefidpersonAdm", query = "SELECT a FROM Assignment a WHERE a.assignmentPK.refidpersonAdm = :refidpersonAdm"), @NamedQuery(name = "Assignment.findByRefidpersonAss", query = "SELECT a FROM Assignment a WHERE a.assignmentPK.refidpersonAss = :refidpersonAss"), @NamedQuery(name = "Assignment.findByRefidticket", query = "SELECT a FROM Assignment a WHERE a.assignmentPK.refidticket = :refidticket")})
public class Assignment implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected AssignmentPK assignmentPK;
    @JoinColumn(name = "REFIDPERSON_ADM", referencedColumnName = "REFIDPERSON", insertable = false, updatable = false)
    @ManyToOne
    private Administrator administrator;
    @JoinColumn(name = "REFIDPERSON_ASS", referencedColumnName = "REFIDPERSON", insertable = false, updatable = false)
    @ManyToOne
    private Assistant assistant;
    @JoinColumn(name = "REFIDTICKET", referencedColumnName = "IDTICKET", insertable = false, updatable = false)
    @ManyToOne
    private Ticket ticket;

    /**
     * Default constructor
     */
    public Assignment() {
    }

    /**
     * Class constructor
     * @param assignmentPK assignment primary key
     */
    public Assignment(AssignmentPK assignmentPK) {
        this.assignmentPK = assignmentPK;
    }

    /**
     * Class constructor
     * @param refidpersonAdm administrator id
     * @param refidpersonAss assistant id
     * @param refidticket ticket id
     */
    public Assignment(int refidpersonAdm, int refidpersonAss, int refidticket) {
        this.assignmentPK = new AssignmentPK(refidpersonAdm, refidpersonAss, refidticket);
    }

    /**
     * 
     * @return assignment primary key
     */
    public AssignmentPK getAssignmentPK() {
        return assignmentPK;
    }

    /**
     * Sets the assignment primary key
     * @param assignmentPK assignment primary key
     */
    public void setAssignmentPK(AssignmentPK assignmentPK) {
        this.assignmentPK = assignmentPK;
    }

    /**
     * 
     * @return administrator reference
     */
    public Administrator getAdministrator() {
        return administrator;
    }

    /**
     * Sets the reference to the administrator
     * @param administrator administrator reference
     */
    public void setAdministrator(Administrator administrator) {
        this.administrator = administrator;
    }

    /** 
     * @return assistant reference
     */
    public Assistant getAssistant() {
        return assistant;
    }

    /**
     * Sets the assistant reference
     * @param assistant assistant reference
     */
    public void setAssistant(Assistant assistant) {
        this.assistant = assistant;
    }

    /**
     * 
     * @return ticket reference
     */
    public Ticket getTicket() {
        return ticket;
    }

    /**
     * Sets the ticket reference
     * @param ticket ticket reference
     */
    public void setTicket(Ticket ticket) {
        this.ticket = ticket;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (assignmentPK != null ? assignmentPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Assignment)) {
            return false;
        }
        Assignment other = (Assignment) object;
        if ((this.assignmentPK == null && other.assignmentPK != null) || (this.assignmentPK != null && !this.assignmentPK.equals(other.assignmentPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "persistence.Assignment[assignmentPK=" + assignmentPK + "]";
    }

}
